//
// Created by wenda.zhao on 2023/2/24.
//

#ifndef NDKPROJECT_SEQUENCERECORDER_H
#define NDKPROJECT_SEQUENCERECORDER_H


#include "DisplayRecorder.h"

class SequenceRecorder {
    typedef std::function<void(char const * fileName)> OnStartCallback;
    typedef std::function<void()> OnFinishCallback;
    typedef std::function<void(int errCode)> OnFailCallback;
public:
    SequenceRecorder(android::PhysicalDisplayId displayId, const char *rootPath,
                     int duration);
    void start();

    void stop();

    void setCallback(OnStartCallback startCallback, OnFinishCallback finishCallback, OnFailCallback failCallback);

    ~SequenceRecorder();

private:
    void next();
    std::string  getFileName();

    void onNext(const char* fileName);
    void onFail(int errCode);
    void onFinish();

private:
    android::PhysicalDisplayId displayId;
    const char *rootPath;
    int duration;

    int count = 0;

    //  记录当前录屏
    DisplayRecorder* currentRecorder = nullptr;

    volatile bool isStopped = false;

    std::function<void(const char* fileName)> drOnStart;
    std::function<void()> drOnFinish;
    std::function<void(int errCode)> drOnFail;

    OnStartCallback onStartCallback;
    OnFinishCallback  onFinishCallback;
    OnFailCallback  onFailCallback;

};


#endif //NDKPROJECT_SEQUENCERECORDER_H
